/* eslint-disable @typescript-eslint/ban-types */
/*
 * @Author: yaoling 1871883713@qq.com
 * @Date: 2022-12-25 21:42:03
 * @LastEditors: yaoling 1871883713@qq.com
 * @LastEditTime: 2022-12-26 14:21:37
 * @FilePath: \pc-file-company\src\apis\login\login.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import hyRequest from '../index'
import Request from '@/apis/index'
import { Itype } from '@/type/index'
import { Account, LoginInfo } from './types'
/**
 * @desc: 获取用户信息
 */
export function getUserInfos(name?: string, password?: string) {
  return Request.post({
    url: '/login',
    method: 'POST',
    data: {
      userName: name,
      passWord: password
    }
  })
}

/**
 * @desc: 修改密码
 */
export function editPassWord(data: Object) {
  return Request.post({
      url: "/admin/changePassWord",
      method: "POST",
      data: data,
  })
}
/**
 * @desc: 删除search参数中的value为空的筛选
 */
const removeNullSearch = (data: Itype | undefined) => {
  for (const key in data) {
    if (key === 'search' && Array.isArray(data[key]) && data[key].length) {
      const search = []
      for (let i = 0; i < data[key].length; i++) {
        if (data[key][i].value) {
          search.push(data[key][i])
        }
      }
      return {
        ...data,
        search
      }
    }
  }
  return data
}
enum LoginAPI {
  AccountLogin = '/login',
  UserInfo = '/users/',
  UserMenus = '/role/'
}
/**
 * @desc: 登录
 */
export function accountLoginRequest(account: Account) {
  return hyRequest.post<LoginInfo>({
    // url: LoginAPI.AccountLogin,
    url: '/api/mapi',
    data: account
  })
}
/**
 * @desc: 获取人员信息
 */
export function getStaffsInfo(data: Object) {
  return hyRequest.post({
    url: '/api/mapi',
    data
  })
}
export const dataInterfaces = (data?: Object, path?: string, method?: string) => {
  return hyRequest.post({
    url: '/login',
    data
  })
}

/**
 * @desc: 用户数据接口
 */
export const dataInterface = (data?: Object, url?: string, method?: string) => {
  return hyRequest.post({
    url: url || 'api/mapi',
    data: removeNullSearch(data),
    method: method || 'POST'
  })
}
